﻿using ModuleBase;
using ModuleBase.googoltech.GTS;

namespace GTSCardSetDo
{
    public class GTSCardSetDo : ModuleBase.ModuleBase
    {
        private int cardNo;

        public int CardNo
        {
            get { return cardNo; }
            set { cardNo = value; }
        }
        private int dINo;

        public int DINo
        {
            get { return dINo; }
            set { dINo = value; }
        }
        private string iOValue = "置位";

        public string IOValue
        {
            get { return iOValue; }
            set { iOValue = value; }
        }
        public override Dictionary<string, object> GetProperties()
        {
            return new Dictionary<string, object>()
            {
                { "卡号",CardNo},
                { "DI",DINo},
                { "操作",IOValue}
            };
        }
        public override Dictionary<string, List<object>> PropertyOptions { get; } = new Dictionary<string, List<object>>
        {
            { "操作" ,new List<object>{ "置位","复位" } },
        };
        public override bool Execute()
        {
            bool keyValuePairs = false;
            int _value = 0;
            if (IOValue == "置位")
            { _value = 0; }
            else
            { _value = 1; }
            GTSCard.SetDo((short)CardNo, (short)DINo, (short)(_value));
            keyValuePairs = true;
            return keyValuePairs;
        }

        public override async Task<bool> ExecuteAsync()
        {
            var result = await Task.Run(() => Execute());
            return result;
        }

        public override void Initialize()
        {

        }
        //写构造函数
        public GTSCardSetDo()
        {
            Name = "SetDo";

            DisplayNameToPropertyNameMap = new Dictionary<string, string>
            {
                { "卡号", nameof(CardNo) },
                { "DI", nameof(DINo) },
                { "操作", nameof(IOValue) },
            };
        }

        public override string Description => "DO信号控制模块：用于设置指定轴卡的数字输出（DO）信号状态（置位/复位）。";
    }
}
